package org.jftstool.auxiliar;

import java.io.ByteArrayInputStream;

import org.jftstool.fileParserFramework.contentHandler.BodyResultHandler;
import org.jftstool.fileParserFramework.exceptions.DocumentHandlerException;
import org.jftstool.fileParserFramework.metadata.DocumentMetaData;
import org.jftstool.fileParserFramework.pdfHandler.PDFHandler;
import org.jftstool.indexer.document.DBDocument;
import org.jftstool.indexer.document.constructor.DBDocumentsExtractor;
import org.jftstool.indexer.document.constructor.DefaultDBDocumentExtractor;
import org.jftstool.indexer.document.exceptions.DBDocumentExtractorException;

public class DBDocumentExtractorTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			DBDocumentsExtractor extractor = new DefaultDBDocumentExtractor();
			extractor.createConnection("MySql");
			extractor.createStatement("DefaultQuery");
			DBDocument doc = null; 
			while ((doc = extractor.next()) != null){
				byte[] buffer = doc.getDocument();
				PDFHandler handler = new PDFHandler();					
				DocumentMetaData metaData = new DocumentMetaData();
				BodyResultHandler result = new BodyResultHandler();
				try {
					handler.getDocument(new ByteArrayInputStream(buffer), result, metaData);
					System.out.println(result.toString());
				}
				catch (DocumentHandlerException e) {
					e.printStackTrace();
				}
			}
		}
		catch (DBDocumentExtractorException e) {
			e.printStackTrace();
		}
	}
}
